package com.cmcc.linlaker.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.cmcc.linlaker.R;
import com.cmcc.linlaker.bean.UpdateBean;

/**
 * Created by zx on 2015/8/14.
 */
public class UpdateDialog extends Dialog implements View.OnClickListener {
    private UpdateBean bean;

    public UpdateDialog(Context context) {
        super(context);
    }

    public UpdateDialog(Context context, UpdateBean bean, int theme) {
        super(context, theme);
        this.bean = bean;
    }

    protected UpdateDialog(Context context, boolean cancelable,
                           OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    private TextView change_log;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.update_dialog);

        change_log = findViewById(R.id.change_log);
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("检测有新版本V" + bean.getVersionShort());
        stringBuffer.append("\n");
        stringBuffer.append("\n");
        stringBuffer.append(bean.getChangelog());
        change_log.setText(stringBuffer.toString());

        TextView cancel_update = (TextView) findViewById(R.id.cancel_update);

        cancel_update.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                onDialogCancelListener.cancel();
            }
        });

        TextView update = (TextView) findViewById(R.id.update);
        update.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                onNewVersionListener.update();
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
        }
    }

    private OnNewVersionListener onNewVersionListener;

    public interface OnNewVersionListener {
        void update();
    }

    public void setNewVersionListener(OnNewVersionListener onNewVersionListener) {
        this.onNewVersionListener = onNewVersionListener;
    }

    private OnDialogCancelListener onDialogCancelListener;

    public interface OnDialogCancelListener {
        void cancel();
    }

    public void setOnDialogCancelListener(OnDialogCancelListener onDialogCancelListener) {
        this.onDialogCancelListener = onDialogCancelListener;
    }
}
